package com.paohe.lianxin_pda.production_line.chengpPei;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.paohe.lianxin_pda.R;

import java.util.ArrayList;
import java.util.List;

public class FragmentTab extends Fragment {

    private ImageView img_fragment;
    private int mPosition;
    private String mTitle = "";

    private RecyclerView mRecyclerView;
    private RecycleAdapter adapter;
    private List<String> list = new ArrayList<String>();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_fragment_tab,null);

        mPosition = getArguments().getInt("position");
        mTitle = getArguments().getString("title");
        img_fragment = view.findViewById(R.id.img_fragment);
        mRecyclerView = view.findViewById(R.id.recycler_view);

        //填充数据
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(linearLayoutManager);
//      获取数据，向适配器传数据，绑定适配器
        list = initData();
        adapter = new RecycleAdapter(getActivity(), list);
        mRecyclerView.setAdapter(adapter);

//      添加动画
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());


        img_fragment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                adapter.addData(list.size());
                //更新数据后定位到最底部
                mRecyclerView.smoothScrollToPosition(adapter.getItemCount()-1);
            }
        });

        return view;
    }

    protected ArrayList<String> initData() {
        ArrayList<String> mDatas = new ArrayList<String>();
        for (int i = 0; i < 1; i++) {
            mDatas.add("" + i);
        }
        return mDatas;
    }
}
